<template>
  <div class="goodsinfo-container">
    <div class="mui-card">
      <div class="mui-card-content">
        <div class="mui-card-content-inner">
          <lbt :lunbotuList="lunbotuList" :isfull="false"></lbt>
        </div>
      </div>
    </div>
    <div class="mui-card">
      <div class="mui-card-header">{{goodsinfo.title}}</div>
      <div class="mui-card-content">
        <div class="mui-card-content-inner">
            <p>市场价:<del>{{goodsinfo.market_price}}</del>&nbsp;&nbsp;销售价:<span class="now_price">￥{{ goodsinfo.sell_price }}</span></p>
            <p>购买数量：<numbox></numbox></p>
            <p>
              <mt-button type="primary" size="small">立即购买</mt-button>
              <mt-button type="danger" size="small">加入购物车</mt-button>
            </p>
        </div>
      </div>
    </div>
    <div class="mui-card">
      <div class="mui-card-header">商品参数</div>
      <div class="mui-card-content">
        <div class="mui-card-content-inner">
          <p>商品货号：{{ goodsinfo.goods_no }}</p>
          <p>库存情况：{{ goodsinfo.stock_quantity }}件</p>
          <p>上架时间：{{ goodsinfo.add_time | dateformat }}</p>
        </div>
      </div>
      <div class="mui-card-footer">
        <mt-button type="primary" size="large" plain @click="goDesc(id)">图文介绍</mt-button>
        <mt-button type="danger" size="large" plain @click="goComment(id)">商品评论</mt-button>
      </div>
    </div>
  </div>
</template>
<script>
import swipe from '../subcomponents/Lunbotu.vue';
import numbox from '../subcomponents/Numbox.vue'
export default {
  data() {
    return {
      id:this.$route.params.id,
      lunbotuList:[],
      goodsinfo:{}
    }
  },
  methods:{
    getGoodsPic(){
      this.$http.get('api/getthumimages/'+this.id).then(result=>{
        if(result.body.status === 0){
          // console.log(result.body.message)
          result.body.message.forEach(item=>{
            item.img = item.src;
          })
          this.lunbotuList = result.body.message;         
        }
      })
    },
    getGoodsInfo(){
      this.$http.get('api/goods/getinfo/'+this.id).then(result=>{
        if(result.body.status === 0){
          console.log(result.body.message)
          this.goodsinfo = result.body.message[0]
        }
      })
    },
    goDesc(id){
      this.$router.push({name:'goodsdesc',params:{id}})
    },
    goComment(id){
      this.$router.push({name:'goodscomment',params:{id}})
    }
  },
  created(){
    this.getGoodsPic();
    this.getGoodsInfo()
  },
  components:{
    lbt:swipe,
    numbox:numbox
  }
}
</script>
<style lang="scss" scoped>
  .goodsinfo-container{
    background-color: #eee;
    overflow:hidden;
    .mui-card-footer{
      display: block;
      button{
        margin: 15px 0;
      }
    }
  }
</style>
